#include "apue.h"
#include <sys/time.h>

void sig_pipe(int val) {
    printf("sig_pipe\n");
}

int main(void) {
    FILE *fpin, *fpout;
    int stat;
    int n;

    // signal(SIGPIPE, sig_pipe);

    if ((fpout= popen("/bin/notexistcmd", "w")) == NULL) {
        err_sys("popen error");
    }

    if ((n= fwrite("hello world", sizeof(char), 11, fpout)) == -1) {
        err_sys("fwrite error");
    }

    sleep(2);
    printf("write %d bytes.\n", n) ;
    sleep(2);
    printf("kakxi");


    if ((stat= pclose(fpout)) == -1) {
        err_sys("pclose error");
    }
    fputs("child termination: ", stdout);
    
    pr_exit(stat);
}
